package com.yesemate.splayer

import android.text.TextUtils
import android.util.Log
import com.yesemate.splayer.util.TimeInfoBean

//播放模式，正常播放
const val PLAY_MODEL_DEFAULT = 1
//播放模式，逐帧播放
const val PLAY_MODEL_FRAME_PREVIEW = 2
class Splayer {
    fun onPrepare() {
        mPlayerListener?.onPrepare()
    }
    var mPlayerListener:PlayerListener?=null
    interface PlayerListener {
        fun onError(code: Int, msg: String?)
        fun onPrepare()
        fun onLoadChange(isLoad: Boolean)
        fun onProgress(currentTime: Long, totalTime: Long)
        fun onTimeInfo(timeInfoBean: TimeInfoBean?)
        fun onEnablePlayChange(enable: Boolean)
        fun onPlayStop()
        fun onComplete()
        fun onDB(db: Int)
        fun onGetVideoInfo(fps: Int, duration: Long, widht: Int, height: Int)
    }

    fun loadMessage(code:Int){
        Log.e(TAG,"结果"+code);
    }


    fun initGetFrame(source:String ){
        //n_init_frame(source);
        n_init_frame_by_ffmepg(source)
    }

    //播放源
    var source:String?=null

    var playModel: Int =PLAY_MODEL_DEFAULT

    fun setModePlay(model:Int){
        playModel = model
        n_palymodel(model)
    }
    private  val TAG = "Splayer"
    fun prepare(){
        Log.e(TAG,"文件路劲"+source)
        source?.let {
          n_parpared(it)
        }
    }
    private var volume = 50;

    var isPlaying: Boolean = false
    var isPause: Boolean = false

    external fun n_play(model:Int);
    fun setVolume( vol:Int=0){
        if (vol <= 0) {
            volume = 0
        } else if (vol > 100){
            volume = 100;
        }else {
            volume=vol;
        }

        n_volume(vol);
    }


    external fun n_volume(vol:Int);

    fun start() {
        if (isPlaying || isPause) {
            return
        }
        if (TextUtils.isEmpty(source)) {
            Log.e("kzg", "source 为空")
            return
        }
        isPlaying = true
        setPlayModel1(playModel)
        setVolume(volume)
//        setPitch(com.example.myplayer.KzgPlayer.pitch)
//        setSpeed(com.example.myplayer.KzgPlayer.speed)
//        setAmplifyVol(com.example.myplayer.KzgPlayer.amplifyVol)
        n_play(playModel)
    }
    fun setPlayModel1(model: Int) {
        playModel = model
        n_palymodel(playModel)
    }

    external fun n_init_frame_by_ffmepg(source:String);
    external fun n_parpared(source:String)
    external fun n_palymodel(model:Int);

    /**
     * A native method that is implemented by the 'splayer' native library,
     * which is packaged with this application.
     */
//    external fun stringFromJNI(): String

    companion object {


        // Used to load the 'splayer' library on application startup.
        init {
            System.loadLibrary("aeditor")
        }
    }
}